<?php

use Biz\model\brandData\ContentCtr;
use Doraemon\amqp\CommunityLevelQueue;
use Doraemon\amqp\CommunityQueue;
use Doraemon\cache\Photos as cPhotos;
use Doraemon\model\AdmNoteOutlineLog;
use Doraemon\model\Photos as dbPhoto;
use Doraemon\service\AdmNote;
use Doraemon\service\Creators\LevelStandard as sLevelStandard;
use Doraemon\service\Note\NoteHandle;
use Doraemon\service\Photos;
use Doraemon\tools\IdParse;

ini_set('display_errors', 1);
error_reporting(-1);
require_once '/data/wwwroot/g_vendor/autoload.php';


$objStrs = $argv[1];

$objIds = explode(',', $objStrs);

exit();

foreach ($objIds as $objId) {

    //设置ctr
    if (!ContentCtr::dataHas(['obj_id' => $objId])) {
        ContentCtr::dataInsert([
            'obj_id' => $objId,
            'ctr' => $argv[2] ?? rand(48, 99) / 10
        ]);
    }

    //设置优质内容
    setGrade($objId);
}


function setGrade($note_id)
{

    $data = [
        'quality' => 2,
        'admin_score' => 70,
        'show_status' => dbPhoto::SHOW_STATUS_NORMAL,
        'status' => dbPhoto::STATUS_SUCCESS
    ];

// 查询更新之前此note的质量
    $photoInfo = Photos::getPhoto($note_id);
    $qualityLastTime = -1;
    if ($photoInfo['quality'] != 2) {
        $qualityLastTime = $photoInfo['quality'];
    }

    $rs = dbPhoto::updatePhotoById($note_id, $data);
    if ($rs) {

        NoteHandle::remarkNote($note_id, "", 1);
        // 添加到队列，更新搜索图片
        cPhotos::delItem($note_id);
        CommunityQueue::insertQueue('queue/photo/editphoto', [
            'photo_id' => $note_id
        ], CommunityQueue::QUEUE_COMMUNITY);

        // 投入wiki服务队列
        \Doraemon\amqp\Queue::insertQueue('queue/wiki/afterAuditContent', [
            'obj_id' => $note_id,
        ], \Doraemon\amqp\Queue::QUEUE_BIZ);

        pushLevelStandard($note_id, $qualityLastTime);

        // log记录
        AdmNote::auditLog($note_id, 2, 'shangjianhong', AdmNoteOutlineLog::AUDIT_CHANNEL_NOTE);

    }
}

// 投入等级判断队列
function pushLevelStandard($noteId, $qualityLastTime)
{
    CommunityLevelQueue::insertQueue('queue/creators/levelStandard', [
        'uid' => IdParse::getUid($noteId),
        'obj_id' => $noteId,
        'event' => sLevelStandard::EVENT_NOTE_ADMIN_SCORE,
        'is_join_brand' => sLevelStandard::NOTE_JOIN_BRAND_UNKNOWN,
        'quality_last_time' => $qualityLastTime,
        'click_type' => 'system_creators_levelStandard'
    ], CommunityLevelQueue::QUEUE_COMMUNITY);
}

